package com.example.deal.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.example.deal.entity.Deal;


@RestController
public class DealController {
	
	@Value("${server.port}")
	private String port; // 注入普通字符串
	
	/**
	 * 从Nacos配置中心获取配置信息
	 */
	@Value("${customized.tittle:}")
    private String title;
	
	@GetMapping("/deal/{id}")
	public Deal findById(@PathVariable Integer id) throws InterruptedException {
		//Thread.sleep(3000);
		Deal deal = new  Deal(id, "Dustyone", "Heyt", 22, 18,port);
		return deal;
	}
	
	@GetMapping("/dealMock/{id}")
	public Deal findByIdMock(@PathVariable Integer id) {
		Deal deal = new  Deal(id, "DustyoneMock", "Mock", 92, 18,port);
		return deal;
	}
	
	@GetMapping("/deal/withoutParams")
	public Deal findByIdWithoutParams() {
		Deal deal = new  Deal(0, "DustyoneMock", "MockWithouParams", 92, 18,port);
		return deal;
	}
	
	@GetMapping("/getConfig")
	public String getConfiguration() {
		return title;
	}
	
	/*@GetMapping("/{id}")
	public Deal findById(@PathVariable Integer id) {
		Deal deal = new  Deal(id, "Dustyone", "Heyt", 22, 18,port);
		return deal;
	}*/
	
}